<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">
        <parent></parent>
    </div>
    <!-- 子组件 -->
    <template id='child'>
        <div>
            <button @click="click">Send</button>
            <input type="text" v-model="message">
        </div>
    </template>
    <!-- 父组件 -->
    <template id='parent'>
        <div>
            <child @childfn="transContent"></child>
            <p>子组件传来的值:{{message}}</p>
        </div>
    </template>
    <script>
        // 注册父组件
        Vue.component('parent',{
            template:'#parent',
            data(){
                return{
                    message:''
                }
            },
            methods:{
                transContent(payload){
                    this.message=payload
                }
            }
        })
        // 注册子组件
        Vue.component('child',{
            template:'#child',
            data(){
                return{
                    message:'子组件消息'
                }
            },
            methods:{
                click(){
                    this.$emit('childfn',this.message)
                }
            }
        })
        const app=new Vue({
            el:'#app',
            data:{},
            methods:{}
        });
    </script>
</body>
</html>